package net.xxcl.news.util;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author Administrator
 * 数据库连接类，用于获取数据库连接
 */
public class DBConnection {

	Connection conn = null;
	final String URL = "jdbc:mysql://127.0.0.1:3306/news";
	final String USER = "root";
	final String PWD = "1";
	
	public DBConnection() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(URL,USER,PWD);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 获取数据库连接
	 * @return
	 */
	public Connection getConnection() {		
		return conn;
	}
	
	/**
	 * 关闭连接
	 */
	public void close() {
		try {
			if(conn!=null) conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
